<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
  <h1>修改商品页面</h1>
  <input type="text" placeholder="id" v-model="p.id" readonly>
  <input type="text" placeholder="标题" v-model="p.title">
  <input type="text" placeholder="价格" v-model="p.price">
  <input type="text" placeholder="库存" v-model="p.num">
  <input type="button" value="修改" @click="update()">
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<script>
  let v = new Vue({
    el:"body>div",
    data:{
      p:{id:"",title:"",price:"",num:""}
    },
    methods:{
      update(){
        //发出异步post请求
          axios.post("/update",v.p).then(function () {
              location.href="/list.html";
          })
      }
    },
    created:function () {
      //发出异步的get请求 location.search得到的是地址栏中的参数 ?id=xxx
      axios.get("/selectById"+location.search).then(function (response) {
        v.p = response.data;
      })
    }
  })
</script>
</body>
</html>